package com.ruoyi.web.controller.business;

import com.ruoyi.business.domain.TMergeOrderDetail;
import com.ruoyi.business.service.ITMergeOrderDetailService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 合并订单明细Controller
 * 
 * @author ruoyi
 * @date 2024-04-04
 */
@Controller
@RequestMapping("/business/mergeOrderDetail")
public class TMergeOrderDetailController extends BaseController
{
    private String prefix = "business/mergeOrderDetail";

    @Autowired
    private ITMergeOrderDetailService tMergeOrderDetailService;

    @RequiresPermissions("business:mergeOrderDetail:view")
    @GetMapping()
    public String mergeOrderDetail()
    {
        return prefix + "/mergeOrderDetail";
    }

    /**
     * 查询合并订单明细列表
     */
    @RequiresPermissions("business:mergeOrderDetail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TMergeOrderDetail tMergeOrderDetail)
    {
        startPage();
        List<TMergeOrderDetail> list = tMergeOrderDetailService.selectTMergeOrderDetailList(tMergeOrderDetail);
        return getDataTable(list);
    }

    /**
     * 导出合并订单明细列表
     */
    @RequiresPermissions("business:mergeOrderDetail:export")
    @Log(title = "合并订单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TMergeOrderDetail tMergeOrderDetail)
    {
        List<TMergeOrderDetail> list = tMergeOrderDetailService.selectTMergeOrderDetailList(tMergeOrderDetail);
        ExcelUtil<TMergeOrderDetail> util = new ExcelUtil<TMergeOrderDetail>(TMergeOrderDetail.class);
        return util.exportExcel(list, "合并订单明细数据");
    }

    /**
     * 新增合并订单明细
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存合并订单明细
     */
    @RequiresPermissions("business:mergeOrderDetail:add")
    @Log(title = "合并订单明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TMergeOrderDetail tMergeOrderDetail)
    {
        return toAjax(tMergeOrderDetailService.insertTMergeOrderDetail(tMergeOrderDetail));
    }

    /**
     * 修改合并订单明细
     */
    @RequiresPermissions("business:mergeOrderDetail:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TMergeOrderDetail tMergeOrderDetail = tMergeOrderDetailService.selectTMergeOrderDetailById(id);
        mmap.put("tMergeOrderDetail", tMergeOrderDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存合并订单明细
     */
    @RequiresPermissions("business:mergeOrderDetail:edit")
    @Log(title = "合并订单明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TMergeOrderDetail tMergeOrderDetail)
    {
        return toAjax(tMergeOrderDetailService.updateTMergeOrderDetail(tMergeOrderDetail));
    }

    /**
     * 删除合并订单明细
     */
    @RequiresPermissions("business:mergeOrderDetail:remove")
    @Log(title = "合并订单明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tMergeOrderDetailService.deleteTMergeOrderDetailByIds(ids));
    }

    @PostMapping("/getMergeOrderDetailList/{id}")
    @ResponseBody
    public TableDataInfo getMergeOrderDetailList(@PathVariable("id") String id)
    {
        startPage();
        TMergeOrderDetail tMergeOrderDetail = new TMergeOrderDetail();
        tMergeOrderDetail.setOrderId(id);
        List<TMergeOrderDetail> list = tMergeOrderDetailService.selectTMergeOrderDetailList(tMergeOrderDetail);
        return getDataTable(list);
    }
}
